package com.itheima.controller;


import com.github.pagehelper.Page;
import com.itheima.anno.Log;
import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    //分页查询
    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
        PageResult pageResult = clazzService.page(empQueryParam);
        return Result.success(pageResult);
    }


    //删除班级
    @Log
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id) throws Exception {
         clazzService.deleteById(id);
         return Result.success();
    }

    //添加班级
    @Log
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        clazzService.addClazz(clazz);
        return Result.success();
    }

    //根据ID查询
    @GetMapping("{id}")
    public Result getInfo(@PathVariable Integer id){
        Clazz clazz = clazzService.getInfo(id);
        return Result.success(clazz);

    }
    @Log
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }
    @GetMapping("list")
    public Result getAllClazz(){
        ArrayList<Clazz> clazzes = clazzService.getAllClass();
        return Result.success(clazzes);
    }


}
